<template>
	<div>
		<el-pagination
			v-model:current-page="currentPage"
			v-model:page-size="pageSize"
			:page-sizes="FieldItem?.attrs['page-sizes']"
			:layout="FieldItem?.attrs.layouts.join(',')"
			:total="(pageData[FieldItem?.vModel_t] || 0) * 1"
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
		/>
	</div>
</template>

<script setup lang="ts">
// 分页器组件
import { TabFieldType } from '/@/components/Linxyun/custom/DataStructs/commontype';
const props = withDefaults(
	defineProps<{
		pageData?: any;
		inputData: Record<string, any>;
		globalData?: any;
		modelValue: string;
		FieldItem: TabFieldType | null;
	}>(),
	{
		pageData: {},
		globalData: {},
		modelValue: '',
		FieldItem: null,
	}
);
const { FieldItem, globalData, pageData } = toRefs(props);
// 页数 vModel_c 页数变量（curret） vModel_l 条数变量（limit）
const currentPage = ref(globalData.value[FieldItem.value?.vModel_c] | 1);
// 每页条数
const pageSize = ref(FieldItem.value?.defaultValue.limit);

const emit = defineEmits(['handleEmitEvent']);

// 每页条数变化
const handleSizeChange = (val: number) => {
	// 赋值给globalData.limit 然后重新查询
	globalData.value[FieldItem.value?.vModel_l] = val;
	emit('handleEmitEvent', 'handleSizeChange', FieldItem.value);
};

//每条页数发生变化 
const handleCurrentChange = (val: number) => {
	globalData.value[FieldItem.value?.vModel_c] = val;
	emit('handleEmitEvent', 'handleCurrentChange', FieldItem.value);
};
</script>

<style lang="scss" scoped></style>
